<script setup lang="ts">
import { width1, width2, isCollapse } from '@/views/layouts/components/collapse'
import { useTabList } from '@/composables/useTabList'

const { activeTab, tabList, changeTab, removeTab, handleCommand } = useTabList()
</script>

<template>
  <div class="f-tag-list" :style="{ left: isCollapse ? width2 : width1 }">
    <el-tabs
      v-model="activeTab"
      type="card"
      class="demo-tabs"
      @tab-remove="removeTab"
      @tab-change="changeTab"
      style="min-width: 100px"
    >
      <el-tab-pane :closable="item.path !== '/'" v-for="item in tabList" :key="item.path" :label="item.title" :name="item.path">
        <!-- {{ item.title }} -->
      </el-tab-pane>
    </el-tabs>
    <span class="tag-btn">
      <el-dropdown @command="handleCommand">
        <span class="el-dropdown-link">
          <el-icon>
            <arrow-down />
          </el-icon>
        </span>
        <template #dropdown>
          <el-dropdown-menu>
            <el-dropdown-item command="closeOther">关闭其他</el-dropdown-item>
            <el-dropdown-item command="closeAll">关闭全部</el-dropdown-item>
          </el-dropdown-menu>
        </template>
      </el-dropdown>
    </span>
  </div>
</template>

<style lang="scss" scoped>
.f-tag-list {
  padding: 4px 10px;
  z-index: 99;

  display: flex;

  // background: #ccc;
  :deep(.el-tabs__header) {
    margin-bottom: 0;
    border: 0 !important;
  }

  :deep(.el-tabs__nav) {
    border: 0 !important;
  }

  :deep(.el-tabs__item) {
    border: 0 !important;
    height: 32px;
    line-height: 32px;
    margin-left: 8px;
    background-color: #fdfdfd;
    border-radius: 5px;
  }

  :deep(.el-tabs__item.is-active) {
    background-color: #fff;
  }

  :deep(.el-tabs__nav-next),
  :deep(.el-tabs__nav-prev) {
    height: 32px;
    line-height: 32px;
    color: #000;
    background-color: #fff;
  }

  :deep(.is-disabled) {
    cursor: not-allowed;
    color: #ccc;
  }

  .tag-btn {
    z-index: 199;
    height: 32px;
    line-height: 32px;
    width: 32px;
    padding: 5px;
    margin-top: 5px;
    background-color: #fff;
    border-radius: 5px;
    margin-left: auto;
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
  }
}
</style>
